<html>
<head><meta charset="utf-8"><title>2 assists with the same action name · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html">2 assists with the same action name</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="187646038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187646038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187646038">(Feb 07 2020 at 15:00)</a>:</h4>
<p><a href="/user_uploads/4715/SmezQNgo5DGXwzkZBGQ8XRZC/pasted_image.png" target="_blank" title="pasted_image.png">pasted image</a> </p>
<div class="message_inline_image"><a href="/user_uploads/4715/SmezQNgo5DGXwzkZBGQ8XRZC/pasted_image.png" target="_blank" title="pasted image"><img src="/user_uploads/4715/SmezQNgo5DGXwzkZBGQ8XRZC/pasted_image.png"></a></div><p>The first one is from <code>add_import.rs</code> and it turns the fully qualified name into an import + the end of the FQN.<br>
The 2nd one is auto import.</p>
<p>I want to change this, any proposals on the naming?</p>



<a name="187646096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187646096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187646096">(Feb 07 2020 at 15:00)</a>:</h4>
<p>it's weird that the 'import ast' shows up when the cursor is on <code>cast</code>, I think</p>



<a name="187646162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187646162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187646162">(Feb 07 2020 at 15:01)</a>:</h4>
<p>on the other hand, importing <code>ast</code> is actually the more useful one here <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="187646929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187646929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187646929">(Feb 07 2020 at 15:10)</a>:</h4>
<p>Yes, we need to auto import <code>ast</code> in such cases IMO, not the <code>cast</code> if we don't modify the string under the caret (which we don't now).</p>
<p>The other question is why do we propose to import the <code>cast</code> in the first place, that's what I tried to debug but instantly got confused by two similarly named actions :)</p>



<a name="187647685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187647685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187647685">(Feb 07 2020 at 15:16)</a>:</h4>
<p>that's the <code>add_import</code> action, which adds an import for a fully qualified path</p>



<a name="187647724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187647724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187647724">(Feb 07 2020 at 15:17)</a>:</h4>
<p>maybe we shouldn't propose that one if the path doesn't actually resolve</p>



<a name="187648242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187648242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187648242">(Feb 07 2020 at 15:21)</a>:</h4>
<p>Damn, I just wanted to quickly ask a naming question without diving into the details <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>
<p><code>ast::UserItem::cast</code> fully resolves, the code compiles, here's the code pointer: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/assists/auto_import.rs#L35" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/assists/auto_import.rs#L35">https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/assists/auto_import.rs#L35</a></p>
<p><code>Import ast::UserItem::cast</code> is brought by the <code>add_import.rs</code>and is fully valid from the functionality point of view: move FQN to <code>use</code> statement, leave the last part of it in the code.<br>
<code>Import ast</code> is brought by <code>auto_import.rs</code> and is not valid at all, it should not appear. I think that happens due to <code>source_analyzer.resolve_path</code> returning <code>None</code>, but that's another thing, I'll bother you about it later.</p>
<p>What I want now is to get rid of two equally named <code>Import ...</code> pop-ups hence asking your opinions on the naming.</p>



<a name="187648451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187648451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187648451">(Feb 07 2020 at 15:23)</a>:</h4>
<p>My opinion: change the <code>add_import.rs</code> one to show the <code>Add import ...</code> pop-up.</p>



<a name="187648637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187648637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187648637">(Feb 07 2020 at 15:25)</a>:</h4>
<p>Well, in this situation one of the actions shouldn't actually be there, so I'm not convinced that the name collision is actually a problem :)</p>



<a name="187648656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187648656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187648656">(Feb 07 2020 at 15:25)</a>:</h4>
<p>Ah is one of these <code>add_import</code> and the other <code>auto_import</code>?</p>



<a name="187648720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187648720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187648720">(Feb 07 2020 at 15:26)</a>:</h4>
<p>If so they should definitely have different labels</p>



<a name="187648790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187648790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187648790">(Feb 07 2020 at 15:27)</a>:</h4>
<blockquote>
<p>Well, in this situation one of the actions shouldn't actually be there, so I'm not convinced that the name collision is actually a problem :)</p>
</blockquote>
<p>That actually makes sense. Still, one more argument for the renaming: if you open the action list twice (first for the unresolved path, then for the resolved path after the auto import), we'll get the same label twice which may be a bit confusing.</p>



<a name="187648924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187648924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187648924">(Feb 07 2020 at 15:28)</a>:</h4>
<p>I think you're both right :)</p>



<a name="187648965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187648965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187648965">(Feb 07 2020 at 15:28)</a>:</h4>
<p>well, you'd have imported <code>ast</code>, and then you'd get the option to import <code>ast::UseItem::cast</code>. I think they're both doing kind of the same thing, adding an import. Writing <code>Add import foo</code> for one and <code>Import foo</code> for the other doesn't really make things clearer for the user</p>



<a name="187649189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187649189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187649189">(Feb 07 2020 at 15:31)</a>:</h4>
<p>Yeah, and I'm almost happy after hearing the latest Florian's idea, funny that I did not think about it from that perspective.</p>
<p>Still confuses me a lot when debugging those false-positives since sometimes I have no idea which label does what :)<br>
But I'll concentrate on the actuall error now, thank you.</p>



<a name="187649704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187649704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187649704">(Feb 07 2020 at 15:37)</a>:</h4>
<p>So what's the difference between add import and auto import?</p>



<a name="187649869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187649869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187649869">(Feb 07 2020 at 15:38)</a>:</h4>
<p>add import works on any qualified path (like <code>a::b::c</code>), adds an import for that path and replaces the original path by the last segment (so <code>use a::b::c; (...) c</code>).<br>
auto import works on a name that doesn't resolve and looks for paths that you could import for it. so you'd have <code>c</code> and it'd find the <code>a::b::c</code> automatically</p>



<a name="187649958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187649958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187649958">(Feb 07 2020 at 15:39)</a>:</h4>
<p>I see. I wouldn't mind if they were the same action.</p>



<a name="187650035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187650035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187650035">(Feb 07 2020 at 15:40)</a>:</h4>
<p>well, effectively they are (as it looks to the user)</p>



<a name="187655643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/2%20assists%20with%20the%20same%20action%20name/near/187655643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/2.20assists.20with.20the.20same.20action.20name.html#187655643">(Feb 07 2020 at 16:42)</a>:</h4>
<p>While in IDE, do as IDEA does:</p>
<p><a href="/user_uploads/4715/yhLCepPo8zZAaC9CDUMdtMc5/pasted_image.png" target="_blank" title="pasted_image.png">pasted image</a> </p>
<div class="message_inline_image"><a href="/user_uploads/4715/yhLCepPo8zZAaC9CDUMdtMc5/pasted_image.png" target="_blank" title="pasted image"><img src="/user_uploads/4715/yhLCepPo8zZAaC9CDUMdtMc5/pasted_image.png"></a></div><p>"Replace qualified path with use"</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>